--[[
	pbc的service，唯一目的是为了初始化probuf解析器的全局地址
]]
local skynet = require "skynet"
require "skynet.manager"
local protobuf = require "protobuf"
local parser = require "parser"
local decode = require "protopack"

local CMD = {}

function CMD.c2sunpack(msgbuf, msgsize)
	return decode.c2sunpack(protobuf, skynet.tostring(msgbuf, msgsize))
end

function CMD.s2cpack(msgname, retcode, retstr, msg)
	return decode.s2cpack(protobuf, msgname, retcode, retstr, msg)
end	

function CMD.get_protobuf_env()
	return protobuf.get_protobuf_env()
end


-- 这里不想自动加载协议目录下的protobuf协议，还是做成需要手工配置的
-- 因为这里的协议定义太重要了。一定要手工设置和检查
function CMD.init(path, filenamelist)
	for _,v in pairs(filenamelist) do
		parser.register(path .."proto/".. v .. ".proto")
	end
	return true
end

function CMD.initproto(filename)
	parser.register(filename)
	return true
end

skynet.dispatch("lua", function (session, address, cmd, ...)
	local f = assert(CMD[cmd])
	skynet.retpack(f(...))
end)

skynet.start(function ()
	skynet.register(".pbcservice")
end)
